﻿using EPiServer.Common.Categories;
using JoelAbrahamsson.MetaWeblog;
using JoelAbrahamsson.TestUtilities;
using Moq;
using StructureMap.AutoMocking;
using Xunit;
using Category=EPiServer.Common.Categories.Category;

namespace JoelAbrahamsson.BlogExtensions.Tests.BlogCategoryProviderTests
{
    public class CreateCategoryInfoTests
    {
        [Fact]
        public void GivenCategory_CreateCategoryInfo_ReturnsCategoryInfoWithTheSameID()
        {
            Mock<ICategory> fakeCategory = new Mock<ICategory>();
            fakeCategory.Setup(category => category.ID).Returns(1);
            fakeCategory.Setup(category => category.Parent).Returns(new Category(RandomValues.String));
            MoqAutoMocker<BlogCategoryProvider> blogCategoryProviderAutoMocker = new MoqAutoMocker<BlogCategoryProvider>();
            blogCategoryProviderAutoMocker.PartialMockTheClassUnderTest();
            BlogCategoryProvider blogCategoryProvider = blogCategoryProviderAutoMocker.ClassUnderTest;

            CategoryInfo categoryInfo = blogCategoryProvider.CreateCategoryInfo(fakeCategory.Object);

            Assert.Equal<string>(fakeCategory.Object.ID.ToString(), categoryInfo.categoryid);
        }

        [Fact]
        public void GivenCategory_CreateCategoryInfo_ReturnsCategoryInfoWithCorrectTitle()
        {
            Mock<ICategory> fakeCategory = new Mock<ICategory>();
            Category parentCategory = new Category(RandomValues.String);
            fakeCategory.Setup(category => category.Parent).Returns(parentCategory);
            fakeCategory.Object.Name = RandomValues.String;
            BlogCategoryProvider blogCategoryProvider = new MoqAutoMocker<BlogCategoryProvider>().ClassUnderTest;

            CategoryInfo categoryInfo = blogCategoryProvider.CreateCategoryInfo(fakeCategory.Object);

            string expectedName = fakeCategory.Object.Parent.Name + BlogCategoryProvider.CategoryNameDelimiter + fakeCategory.Object.Name;
            Assert.Equal<string>(expectedName, categoryInfo.title);
        }
    }
}